export const globalfun = {
	uploadone() {
		console.log('1111');
		return new Promise((resolve, reject) => {
			try {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (res) => {
						let tempFilePath = res.tempFilePaths[0];
						let header = {
							'token': uni.getStorageSync('userToken') || '',
							'content-type': 'application/x-www-form-urlencoded'
						}
						uni.showLoading({
							title: '上传中...'
						});
						const BASEURL = getApp().globalData.BASEURL
						uni.uploadFile({
							url: BASEURL + '/api/aliyun/oss/upload',
							filePath: tempFilePath,
							name: 'file',
							header: header,
							success: (res1) => {
								let data = JSON.parse(res1.data)
								if (res1.statusCode == 200 && data.code ==
									200) {
									let res = data.url
									uni.hideLoading();
									resolve(res)
								} else {
									uni.showToast({
										title: res1.data.msg,
										icon: "none",
										duration: 1500
									});
								}
							}
						});
					},
					fail: (err) => {}
				});
			} catch (e) {
				reject(e)
			}
		})
	},
	previewImage(list, index) {
		uni.previewImage({
			current: index,
			urls: list,
			longPressActions: {
				itemList: ['发送给朋友', '保存图片', '收藏'],
				success: function(data) {
					console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
				},
				fail: function(err) {
					console.log(err.errMsg);
				}
			}
		});
	},
	pageGoTs: url => {
		uni.switchTab({
			url
		})
	},
	pageTo: url => {
		uni.navigateTo({
			url
		})
	},
	phoneCall: number => {
		uni.makePhoneCall({
			phoneNumber: number, //仅为示例
			success: function() {
				console.log('success');
			}
		});
	},
	opennavigation: data => {
		uni.openLocation({
			name: data.address_info,
			latitude: parseFloat(data.latitude),
			longitude: parseFloat(data.longitude),
			success: function() {
				console.log('success');
			}
		});
	},
	copyFun: data => {
		uni.setClipboardData({
			data, // 要复制的内容
			success: () => { // 复制成功回调
				console.log('11');
				uni.showToast({
					title: '已复制',
					icon: 'success'
				})
			}
		});
	},
}